#include "prec.h"
#include "mainframe.h"
#include "wx/log.h"
#include "wx/panel.h"

#define TIMERID (100023)

BEGIN_EVENT_TABLE(MainFrame, wxFrame)
	EVT_SIZE(MainFrame::OnSize)
	EVT_TIMER(TIMERID, MainFrame::OnTimer)
	EVT_CLOSE(MainFrame::OnCloseWindow)
END_EVENT_TABLE()


MainFrame::MainFrame()
: wxFrame(NULL, wxID_ANY, wxT("MainFrame"), wxDefaultPosition, wxDefaultSize, wxMAXIMIZE|wxSTAY_ON_TOP|wxTAB_TRAVERSAL)
{
	InfoPage* infopage = new InfoPage(this);
	AddPage(infopage);

	m_mainPage = new MainPage(this);
	AddPage(m_mainPage);

	SetActivePage(0);

	m_timer = new wxTimer(this, TIMERID);
	m_timer->Start(1000);
}

void MainFrame::OnSize( wxSizeEvent& evt )
{
	wxSize s = evt.GetSize();
	wxRect r(0, 0, s.GetWidth(), s.GetHeight());
	SetRect(r);
}

void MainFrame::OnTimer( wxTimerEvent& evt )
{
	wxDateTime now = wxDateTime::Now();
	if (m_mainPage->IsShown())
		m_mainPage->UpdateTime(now);
}

void MainFrame::OnCloseWindow( wxCloseEvent& event )
{
	m_timer->Stop();
	event.Skip();
}